home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 511 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.0 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.sys.hp.hpux,comp.std.c,comp.lang.c
  4. Subject: Re: struct init problem
  5. Date: Wed, 06 Mar 96 14:30:18 GMT
  6. Organization: none
  7. Distribution: na
  8. Message-ID: <826122618snz@genesis.demon.co.uk>
  9. References: <DnrAEx.HA@tpoint.net> <826101714snz@wbriscoe.demon.co.uk>
  10. Reply-To: fred@genesis.demon.co.uk
  11. X-NNTP-Posting-Host: genesis.demon.co.uk
  12. X-Newsreader: Demon Internet Simple News v1.27
  13. X-Mail2News-Path: genesis.demon.co.uk
  14.  
  15. In article <826101714snz@wbriscoe.demon.co.uk>
  16.            walter@wbriscoe.demon.co.uk "walter briscoe" writes:
  17.  
  18. >In article <DnrAEx.HA@tpoint.net> devil@tpoint.net "The Devil Himself" writes:
  19. >
  20. >> I found that the attached code does not compile on HP's, but does compile on
  21. >> UNIXware, etc. I'd like to hear any ideas beside my hacked solution.
  22. >> I'm looking for a way to preserve using the struct = { .... } syntax.
  23. >> 
  24. >> Also, who you characterize this problem vs. ansi C.....
  25. >
  26. >[snip]
  27. >
  28. >>         int     ima_int = 0xdeadbeef ;
  29. >>         {
  30. >>                 struct test_me please = 
  31. >>                 {
  32. >>                         0xbeefdead ,
  33. >>                         & ima_int 
  34. >>                 } ;
  35. >> 
  36. >>         /*
  37. >>          * NOTE: HP-UX foo A.09.05 A 9000/712
  38. >>          * wont compile this & ima_int statement, unless I declare
  39. >>          * BOTH ima_int AND please as "static". unfortunately, I want this
  40. >>          * code to be reenterant.
  41. >>          */
  42.  
  43. Compound initialisers must consist of constant expression which means that
  44. ima_int must have static storage duration for this code to be portable.
  45. There is no requirement for please to be static. However if you are using
  46. a pre-ANSI compiler in the HP-UX system there is a good chance that it
  47. won't accept auto struct initialisation. If ima_int really needs to be
  48. an auto variable (you mentioned recursion) then you can't use structure
  49. initialisation portably.
  50.  
  51. >As an aside. ints > 16 bits are unportable. long portably meets your
  52. >needs.
  53. >
  54. >I regret that the code does not conform with ANSI/ISO 9899-1990.
  55. >
  56. >> 6.5.7 Initialization
  57. >
  58. >[snip]
  59. >
  60. >> All the expressions in an initializer for an object that has static
  61. >> storage duration or in an initializer list for an object that has
  62. >> aggregate or union type shall be constant expressions.
  63. >>
  64. ...
  65.  
  66. >The address of ima_int is not known at translate time.  I would argue
  67. >that any implementation which allows a source containing this code to be
  68. >translated without producing a diagnostic is not conforming because:
  69.  
  70. You're missing the following in 6.4:
  71.  
  72. "An implementation may accept other forms of constant expressions."
  73.  
  74. So the UNIXware compiler can legally accept &ima_int as a constant
  75. expression so long as it does so consistently. However code that uses
  76. this isn't strictly conforming.
  77.  
  78. -- 
  79. -----------------------------------------
  80. Lawrence Kirby | fred@genesis.demon.co.uk
  81. Wilts, England | 70734.126@compuserve.com
  82. -----------------------------------------
  83.